#include "myhead.h"

/*
	双向
	有名管道用于两个没有任何关系的进程间通信 
*/

int main()
{
	int ret;
	int fd;
	char buf[100];
	char otherbuf[100];
	
	//创建有名管道
	ret = mkfifo("/home/gec/mysecond",0777);
	if(ret == -1){
		printf("error number is : %d\n",errno);
		perror("mkfifo");
		return -1;
	}
	//打开你刚才新建的那个管道文件
	fd = open("/home/gec/mysecond",O_RDWR); 
	if(fd == -1){
		perror("open");
		return -1;
	}
	//给p2发送信息
	while(1){
		bzero(buf,100);
		bzero(otherbuf,100);
		printf("input information to p2:\n");
		scanf("%s",buf);
		write(fd,buf,strlen(buf)); 
		sleep(1);
		if(strcmp(buf,"quit")==0){
			break;
		} 
		read(fd,otherbuf,100);
		printf("p2 say :%s\n",otherbuf);
	} 
	close(fd);

}
